package com.sanji.sjmallmodule.login;

import android.widget.BaseAdapter;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.sanji.sjmallapp.R;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by zsf on 16-12-28.
 */

public class RegisterRegionAdpter extends BaseAdapter {
    private List<RegisterRegionBean> mData;
    private Context context;

    public RegisterRegionAdpter(List<RegisterRegionBean> mData, Context context) {
        this.mData = mData;
        this.context = context;
    }

    public void notifyAdapter(List<RegisterRegionBean> list) {
        this.mData = list;
        this.notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return mData.size();
    }

    @Override
    public Object getItem(int i) {
        return mData.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder viewHolder;
        if (view == null) {
            view = LayoutInflater.from(context).inflate(R.layout.activity_popwindow_register_item, null);
            viewHolder = new ViewHolder(view);
            view.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) view.getTag();
        }
        //捆绑数据
        RegisterRegionBean bean = mData.get(i);
        if (bean.isSelect()) {
            viewHolder.popRegionImg.setVisibility(View.VISIBLE);
        } else {
            viewHolder.popRegionImg.setVisibility(View.GONE);
        }
        viewHolder.popRegionName.setText(bean.getRegionName());
        return view;
    }


    static class ViewHolder {
        @BindView(R.id.pop_region_name)
        TextView popRegionName;
        @BindView(R.id.pop_region_img)
        ImageView popRegionImg;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
